<HEAD>
  <SCRIPT SRC="../ganja.js"></SCRIPT>
</HEAD>
<BODY><SCRIPT>
// Create a Clifford Algebra with 2,0,1 metric. 
Algebra(2,0,1,()=>{
  
  // The core elements of 2D PGA (from ex. 1)
  var point = (x,y)=>!(1e0 + x*1e1 + y*1e2),    
      line  = (a,b,c)=>a*1e1 + b*1e2 + c*1e0;
     
  // The universal distance/angle formulas (from ex. 2)     
  var dist  = (x,y)=>(x & y).Length,
      angle = (x,y)=>Math.acos(x | y);
      
  // Similar, projecting and rejecting elements in PGA
  // is unified with the same formula for points and lines.
  var project = (a,b)=>(a | b) / b,
      reject  = (a,b)=>(a | b);    
    
  // Define some points and lines.
  var A = point(1, 1), 
      B = point(-1, 1), 
      C = point(-1, -1), 
      AC= ()=>A & C;
  
  // Graph the projections/rejection between B and AC
  document.body.appendChild(this.graph([
    "Project, Reject","Drag the points",
    0xD0FFE1, [A,B,C],    
    0x882288, ()=>project(B, AC), "project B onto AC",
    0x882288, ()=>project(AC, B), "project AC onto B",
    0x008844, ()=>reject(AC, B),  "reject AC from B",
    0x00AA88, AC, "AC",
    0x224488, A, "A", B, "B", C, "C",
  ],{lineWidth:3, grid:true, labels:true}));
  
});
</SCRIPT></BODY>